<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <link rel="StyleSheet" type="text/css" href="/tpa/jquery-ui.css" />
      <link rel="StyleSheet" type="text/css" href="/tpa/admin.css" />
      <link rel="StyleSheet" type="text/css" href="/tpa/jquery.Jcrop.css" />
      <link rel="stylesheet" type="text/css" href="/lib/el/css/elrte.css" media="screen">
      <link rel="stylesheet" type="text/css" href="/lib/el/css/elfinder.css" media="screen">
      <link rel="StyleSheet" type="text/css" href="/tpa/jqgrid.css" />
      
      <script type="text/javascript" src="/lib/js/jquery.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.ui.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.Jcrop.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.maskedinput.js"></script>
      <script type="text/javascript" src="/lib/js/swfobject.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.uploadify.js"></script>
      <script type="text/javascript" src="/lib/el/elrte.js"></script>
      <script type="text/javascript" src="/lib/el/elfinder.js"></script>
      <script type="text/javascript" src="/lib/el/i18n/elrte.{%$lang.iso%}.js"></script>
      <script type="text/javascript" src="/lib/el/toolbars.js"></script>
      <script type="text/javascript" src="/lib/js/meccano.js"></script>
      <script type="text/javascript" src="/admin/thumbnailing.php"></script>
      <script type="text/javascript" src="/lib/js/localization/grid.locale-{%$lang.alias%}.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.jqGrid.js"></script>
      
      {%ErrorHandler->getSuccess assign='make'%}
      
      <script type="text/javascript">
         {%strip%}{%foreach from=$langs item='l' name='i'%}
         {%if $smarty.foreach.i.first%}
         var langs = [
            {%/if%}
            {'id':'{%$l.id%}','alias':'{%$l.alias%}','title':'{%$l.title%}'}
            {%if !$smarty.foreach.i.last%},{%/if%}
            {%if $smarty.foreach.i.last%}
         ];
         {%/if%}
         {%/foreach%}{%/strip%}
         var default_lang = {%$default_lang%};
         var current_lang = {%$default_lang%};
         var editors = {};

         $(document).ready(function(){
            // INIT TABS
            $('#tabedContent').tabs();
            {%if !$DataObject->id%}$('#tabedContent').tabs( "disable", ($('ul.fields_tabs li').size() - 1));{%/if%}
            
            $("#articlesList").jqGrid({
               url:'/api.json',
               editurl: '/api.json',
               serializeGridData : function(postdata) {
                  var d = {
                     'method': 'articles.get',
                     'data': {
                        'cat': '{%$DataObject->id%}'
                     }
                  };
                  d.data = $.extend(d.data, postdata);
                  return d;
               },
               colNames:[
                  'ID',
                  '{%$TR->meccano->title|escape:"javascript"%}', 
                  '{%$TR->meccano->date|escape:"javascript"%}',
                  '{%$TR->datatypes->category|escape:"javascript"%}', 
                  '{%$TR->meccano->views|escape:"javascript"%}',
               ],
               colModel:[
                  {name:'id',index:'id', width:55},
                  {name:'title',index:'title'},
                  {name:'sdate',index:'sdate',align:"right"},
                  {name:'category',index:'cat'},
                  {name:'views',index:'views',align:"right"}
               ],
               rowNum:{%$CONFIG->system('items')%},
               rowList:[{%$CONFIG->system('items')%},{%$CONFIG->system('items')*2%},{%$CONFIG->system('items')*4%}],
               pager: '#articlesPager',
               width:'100%',
               height: '100%',
               datatype: "json",
               viewrecords: true,
               multiselect: true,
               ondblClickRow: function(i){window.location.href = '/admin/article/'+i+'.html';}
            });
            $("#articlesList").jqGrid(
               'navGrid',
               '#articlesPager',
               {edit:true,add:false,del:true,search:true},
               {
                  beforeInitData: function(){
                     var i;
                     i = jQuery(this).jqGrid('getGridParam','selrow');
                     window.location.href = '/admin/article/'+i+'.html';
                     return false;
                  }
               }, // EDIT OPTIONS
               {}, // ADD OPTIONS
               {
                  serializeDelData:  function(postdata) {
                     var d = {
                        'method': 'articles.delete',
                        'data': {
                           'id': postdata.id
                        }
                     };
                     return d;
                  }
               }, // DEL OPTIONS
               {
                  beforeShowSearch: function()
                  {
                     alert('hello');
                     return false;
                  }
               } // SEARCH OPTIONS
            );
            
            // jqGrid TODO: column Chooser
            
            
            //SwitchLang(default_lang);
            {%if $make%}{%$make.exec%}({%$make.result%});{%/if%}
            {%if count($langs) > 1%}$('#lang_tabs').tabs();{%/if%}
            $('.wyswyg').each(function(){
              field_id = $(this).attr('id');
               var opts = {
                  lang: '{%$lang.iso%}',
                  styleWithCSS : false,
                  height       : $(this).height(),
                  toolbar      : $(this).data('emode'),
                  cssfiles: ["/usr/css/elrt.css"]
               };
               editors[field_id] = new elRTE(this, opts);
               editors[field_id].val(document.getElementById('f_'+field_id+'_'+default_lang).value);
            });
         });

      </script>
   </head>
   <body>
      <form action="/admin/category{%if $DataObject->id != NULL%}/{%$DataObject->id%}{%else%}/{%$under_category%}/new{%/if%}.html" name="FORM_category" method="POST" enctype="multipart/form-data">
         <div style="padding: 5px 0 0 30px; height: 15px; overflow: hidden;"><span style="color:#777;">{%$TR->datatypes->category%}</span>: <b> {%$DataObject->title%}</b></div>
         <div id="tabedContent">

            <input type="hidden" name="commit" value="1" />

            <ul class="fields_tabs">
            {%foreach from=$DataObject->getFields() key='tab_id' item='field_set'%}

               {%if $field_set->active eq 1%}
               <li><a href="#t_fields_{%$tab_id%}"><span>{%$field_set->title%}</span></a></li>
               {%/if%}
            {%/foreach%}
               <li><a href="#t_fields_a" title="t_fields_a"><span>{%$TR->meccano->articles%}</span></a></li>
            </ul>
            
            {%foreach from=$DataObject->getFields() key='tab_id' item='field_set' name='i'%}
            <div id="t_fields_{%$tab_id%}">

               <!-- TAB: {%$field_set->title%} -->

               {%if $field_set->fieldset && $field_set->active%}

               {%$field_set->getFieldHTML($DataObject)%}
               
               {%else%}

               <table width="100%" border="0">
                  <col width="150">
                     <tbody>

                        {%foreach from=$field_set->fields item=field%}
                        {%if $field->active eq 1%}

                        <tr>
                           <td class="rt">
                              <label for="f_{%$field->alias%}" title="{%$field->alias%}">{%$field->title%}:</label>
                           </td>
                           <td>
                              {%$field->getFieldHTML($DataObject)%}
                           </td>
                        </tr>

                        {%/if%}
                        {%/foreach%}
                     </tbody>
               </table>

               {%/if%}

               <!-- EOF TAB: {%$field_set->title%} -->


            </div>
            {%/foreach%}
            
            <div id="t_fields_a">

               <table id="articlesList"></table>
               <div id="articlesPager"></div>

            </div>


         </div>

         <div style="margin:10px 0 0 15px;">
            <input type="button" value=" {%$TR->meccano->save%} " onclick="CommitForm('FORM_category');" />
         </div>

      </form>

      {%if count($langs) > 1%}
      <div id="lang_tabs">
      {%foreach from=$langs item='l' name='i'%}
      {%if $smarty.foreach.i.first%}<ul>{%/if%}
         <li><a href="#l_{%$l.id%}" onclick="SwitchLang({%$l.id%});"><span>{%$l.title%}</span></a></li>
         {%if $smarty.foreach.i.last%}</ul>
         {%/if%}
      {%/foreach%}
      {%foreach from=$langs item='l' name='i'%}
      <div id="l_{%$l.id%}"></div>
      {%/foreach%}
      </div>
      {%/if%}

   </body>
</html>